import dt from '@dt/dt'
import Opt from '@/components/dt/info/Opt.js'
import ruleOpt from '@/biz/option/rule.js'

class ConfigOpt extends Opt {
  constructor(info) {
    super(info)
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }
  rules() {
    return this.info.operation == 'NO_PASS' ? [ruleOpt.required('请填写审批内容')] : []
  }

  createAll() {
    console.log(this.info, 1111222)
    this.all = [
      [
        {
          title: '案场名称',
          key: 'housesName',
          col: 12,
          text: {}
        },
        {
          title: '申请月份',
          key: 'applyMonth',
          col: 12,
          text: {}
        }
      ],
      [
        {
          title: '延期原因',
          key: 'extendReason',
          col: 12,
          text: {
            type: 'dict',
            key: 'bonusExtendReason'
          }
        },
        {
          title: 'OA文电编号',
          key: 'oaNumber',
          col: 12,
          text: {}
        }
      ],
      {
        title: '备注',
        key: 'remark',
        col: 24,
        text: {}
      },
      [
        {
          title: '提交人',
          key: 'createUserName',
          col: 12,
          text: {}
        },
        {
          title: '提交时间',
          key: 'createTime',
          col: 12,
          text: {
            tooltip: false
          }
        }
      ],
      {
        title: '状态',
        key: 'status',
        visible: this.info.__type != 'approve',
        col: 24,
        text: {
          type: 'dict',
          key: 'bonusExtendStatus'
        }
      },
      {
        title: '审批内容',
        key: 'approveContent',
        visible: this.info.__type != 'approve',
        col: 24,
        text: {}
      },
      [
        {
          title: '处理人',
          key: 'updateUserName',
          visible: this.info.__type != 'approve',
          col: 12,
          text: {}
        },
        {
          title: '处理时间',
          key: 'updateTime',
          visible: this.info.__type != 'approve',
          col: 12,
          text: { tooltip: false }
        }
      ]
    ]
    let approve = [
      {
        title: '审批结果',
        key: 'operation',
        placeholder: '请选择',
        select: {
          options: [
            { key: 'PASS', value: '通过' },
            { key: 'NO_PASS', value: '不通过' }
          ]
        },
        associationRules: ['approveContent'],
        change: () => {
          approve[1].rules = this.rules()
        },
        rules: [ruleOpt.required('请选择审批结果')]
      },
      {
        title: '审批内容',
        key: 'approveContent',
        col: 20,
        input: {
          type: 'textarea',
          autosize: {
            minRows: 4
          },
          maxlength: 200
        },
        rules: this.rules()
      }
    ]
    if (this.info.__type == 'approve') {
      this.all.push([...approve])
    }
  }
}

export default ConfigOpt
